package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.domain.EduTeacher;
import com.ruoyi.system.service.IEduTeacherService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.EduKlass;
import com.ruoyi.system.service.IEduKlassService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 班级Controller
 * 
 * @author ruoyi
 * @date 2024-03-25
 */
@Controller
@RequestMapping("/system/klass")
public class EduKlassController extends BaseController
{
    private String prefix = "system/klass";

    @Autowired
    private IEduKlassService eduKlassService;

    @Autowired
    private IEduTeacherService eduTeacherService;

    @RequiresPermissions("system:klass:view")
    @GetMapping()
    public String klass()
    {
        return prefix + "/klass";
    }

    /**
     * 查询班级列表
     */
    @RequiresPermissions("system:klass:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EduKlass eduKlass)
    {
        startPage();
        List<EduKlass> list = eduKlassService.selectEduKlassList(eduKlass);
        return getDataTable(list);
    }

    /**
     * 导出班级列表
     */
    @RequiresPermissions("system:klass:export")
    @Log(title = "班级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EduKlass eduKlass)
    {
        List<EduKlass> list = eduKlassService.selectEduKlassList(eduKlass);
        ExcelUtil<EduKlass> util = new ExcelUtil<EduKlass>(EduKlass.class);
        return util.exportExcel(list, "班级数据");
    }

    /**
     * 新增班级
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("teachers", eduTeacherService.selectTeacherAll());
        return prefix + "/add";
    }

    /**
     * 新增保存班级
     */
    @RequiresPermissions("system:klass:add")
    @Log(title = "班级", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EduKlass eduKlass)
    {
        return toAjax(eduKlassService.insertEduKlass(eduKlass));
    }

    /**
     * 修改班级
     */
    @RequiresPermissions("system:klass:edit")
    @GetMapping("/edit/{klassId}")
    public String edit(@PathVariable("klassId") Long klassId, ModelMap mmap)
    {
        EduKlass eduKlass = eduKlassService.selectEduKlassByKlassId(klassId);
        mmap.put("eduKlass", eduKlass);
        List<EduTeacher> teachers = eduTeacherService.selectTeacherAll();
        mmap.put("teachers", teachers);
        return prefix + "/edit";
    }

    /**
     * 修改保存班级
     */
    @RequiresPermissions("system:klass:edit")
    @Log(title = "班级", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EduKlass eduKlass)
    {
        return toAjax(eduKlassService.updateEduKlass(eduKlass));
    }

    /**
     * 删除班级
     */
    @RequiresPermissions("system:klass:remove")
    @Log(title = "班级", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(eduKlassService.deleteEduKlassByKlassIds(ids));
    }
}
